package com.example.tys.daggermvp.dagger2.module;

import com.example.tys.daggermvp.dagger2.annotation.ActivityScoped;
import com.example.tys.daggermvp.mvp.contract.MainActivity2Contract;
import com.example.tys.daggermvp.mvp.contract.PlusOneFragmentContract;
import com.example.tys.daggermvp.mvp.module.PlusOneFragmentData;
import com.example.tys.daggermvp.mvp.presenter.MainActivity2Presenter;
import com.example.tys.daggermvp.mvp.presenter.PlusOneFragmentPresenter;
import com.example.tys.daggermvp.mvp.view.Main2Activity;
import com.example.tys.daggermvp.mvp.view.PlusOneFragment;
import com.example.tys.daggermvp.dagger2.annotation.FragmentScoped;

import dagger.Module;
import dagger.Provides;
import dagger.android.ContributesAndroidInjector;

/**
 * Activity 对应的Module。在ActivityBindingModule中设置对应关系
 *
 * @author tys
 * @date 2018/4/14
 */
@Module
public abstract class MainActivity2Module {

    //Fragment申明 + Fragment构造函数@Inject

    @FragmentScoped
    @ContributesAndroidInjector
    abstract PlusOneFragment plusOneFragment();
    /*================================================================================================*/

    @ActivityScoped
    @Provides
    static MainActivity2Contract.Presenter provideMainActivity2Presenter(Main2Activity main2Activity) {
        return new MainActivity2Presenter();
    }

    @ActivityScoped
    @Provides
    static MainActivity2Contract.Date provideMainActivity2DataModule(Main2Activity main2Activity) {
        //provides 不允許返回null
        return new MainActivity2Contract.Date() {};
    }

    /*================================================================================================*/

    @ActivityScoped
    @Provides
    static PlusOneFragmentContract.Presenter plusOneFragmentPresenter(Main2Activity main2Activity) {
        return new PlusOneFragmentPresenter();
    }

    @ActivityScoped
    @Provides
    static PlusOneFragmentContract.Data plusOneFragmentDataModule(Main2Activity main2Activity) {
        return new PlusOneFragmentData();
    }

    /**
     * MainActivity2Presenter 构造方法必须 @Inject
     *
     * @param presenter 返回的实际类型
     * @return
     */
//    @ActivityScoped
//    @Binds
//    abstract MainActivity2Contract.Presenter MainActivity2Presenter(MainActivity2Presenter presenter);

    /**
     * Provides, static产出变量
     * 可用于MainActivity2Presenter 构造函数.或者Main2Activity成员属性
     *
     * @param activity 当前注入Activity的实例
     * @return
     */
//    @Provides
//    @ActivityScoped
//    static MainActivity2Contract.View provideView(Main2Activity activity) {
//        return activity;
//    }
}
